package pers.lance.firstweb.dao;

import pers.lance.firstweb.bean.User;

import java.util.Date;
import java.util.List;
import java.util.Vector;

/**
 *
 */
public class UserManagerImpl implements UserManager {

    private static List<User> users = new Vector<User>();

    static {
        for (int i = 0; i < 5; i++) {
            users.add(new User(i, "name" + i, "password" + i, new Date(), "major" + i));
        }
    }

    @Override
    public int addUser(User u) {
        u.setId(users.size() + 1);
        users.add(u);
        return 0;
    }

    @Override
    public User loadUser(String name) {
        for (User user : users) {
            if (user.getName().equals(name)) {
                return user;
            }
        }
        return null;
    }

    @Override
    public List<User> findAllUsers() {
        return users;
    }

}
